﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WeChatTool
{
	public class ShortcutInfo
	{
		public string Name { get; set; }
		public string FilePath { get; set; }
		public string TargetPath { get; set; }
		public string Arguments { get; set; }
		public string WorkDir { get; set; }
	}

	public static class ShortcutEx
	{

		/// <summary>
		/// 读取一个快捷方式的信息
		/// </summary>
		/// <param name="lnkFilePath"></param>
		/// <returns></returns>
	   public static	ShortcutInfo ReadShortcut(this string lnkFilePath)
		{
			if (!File.Exists(lnkFilePath))
				return null;
			else
			{
				var shellType = Type.GetTypeFromProgID("WScript.Shell");
				dynamic shell = Activator.CreateInstance(shellType);
				var shortcut = shell.CreateShortcut(lnkFilePath);
				return new ShortcutInfo()
				{
					Name = Path.GetFileName(lnkFilePath),
					TargetPath = shortcut.TargetPath,
					Arguments = shortcut.Arguments,
					WorkDir = shortcut.WorkingDirectory,
					FilePath = lnkFilePath,
				};
			}
		}
	}
}
